import Vue from 'vue'
import Router from 'vue-router'
import routes from './default'
// import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

// NProgress.configure({ showSpinner: false });

Vue.use(Router)

const router = new Router({
  routes,
})

// router.beforeEach((to, from, next) => {
//   // NProgress.start()
//   if (to.matched.length === 0) {
//     // NProgress.done()
//     next({
//       path: '/404'
//     })
//   } else {
//     next()
//   }
//   // NProgress.done()
// })

const VueRouterPush = Router.prototype.push
Router.prototype.push = function push (to) {
  return VueRouterPush.call(this, to).catch(err => err)
}

const originalReplace = Router.prototype.replace;
Router.prototype.replace = function replace(location) {
  return originalReplace.call(this, location).catch(err => err);
};

export default router
